import org.junit.Test;

import java.io.*;
import java.nio.charset.StandardCharsets;

public class FileChangeTest {
    public static void main(String[] args) {

    }

    @Test
    public void testFileChange() {
        File file1 = new File("change_gbk.txt");
        File file2 = new File("change_utf8.txt");
        try (
                FileInputStream fis = new FileInputStream(file1);
                InputStreamReader isr = new InputStreamReader(fis, "GBK");
                FileOutputStream fos = new FileOutputStream(file2);
                OutputStreamWriter osw = new OutputStreamWriter(fos, StandardCharsets.UTF_8);
                ) {
            int len;
            char[] buf = new char[1024];
            while ((len = isr.read(buf)) != -1) {
               osw.write(buf, 0, len);
            }
            System.out.println("操作成功");
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
